<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Contract-add</title>
    <!-- 引入layui 样式-->
    <link rel="stylesheet" href="../../static/css/style.css"/>
    <link rel="stylesheet" href="../../static/layer/css/layui.css"/>
    <link rel="stylesheet" href="../../static/css/font-awesome.min.css">
    <link rel="stylesheet" href="../../static/ucss/contract/loan.css"/>
    <style>
        .layui-form-label {
            width: 100px;
        }
    </style>
</head>

<body>
<form class="layui-form">
    <div class="layui-tab layui-tab-brief" lay-filter="contractInfoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this">基本信息</li>
            <li class="contractInfo">合同信息</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="tab-body">
                    <div>
                        <div class="quote-submit-person">
                            <span>提交人： <span class="user_name"></span></span>
                        </div>
                        <div class="quote-tenant-info">
                            <div class="quote-title">
                                <i class="fa fa-circle-o" aria-hidden="true"></i>
                                <span>借款方信息</span>
                            </div>
                            <div class="tenant-box">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">出借方</label>
                                        <div class="layui-input-inline">
                                            <input type="radio" name="TRNANTRY" value="0" title="公司出借"
                                                   lay-filter="rent-type" checked="">
                                            <!--<input type="radio" name="TRNANTRY" value="1" title="个人出借"
                                                   lay-filter="rent-type">-->
                                        </div>
                                        <div class="width10"></div>
                                    </div>
                                    <!--<div class="layui-inline">
                                        <label class="layui-form-label">合同编号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="CONTRACT_NUM" id="contractNum" lay-verify="required" autocomplete="off"
                                                   class="layui-input required_fields">
                                        </div>
                                        <div class="layui-form-mid-red">*</div>
                                    </div>-->
                                    <div class="layui-inline company-input">
                                        <label class="layui-form-label">公司名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="COMPANY" lay-verify="required" autocomplete="off"
                                                   class="layui-input required_fields">
                                        </div>
                                        <div class="layui-form-mid-red">*</div>

                                    </div>
                                    <div class="layui-inline person-input" style="display: none;">
                                        <label class="layui-form-label">姓名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="NAME" lay-verify="required" autocomplete="off"
                                                   class="layui-input required_fields">
                                        </div>
                                        <div class="layui-form-mid-red">*</div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">别名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="byname" lay-verify="required" autocomplete="off"
                                                            class="layui-input">
                                        </div>
                                        <div class="width10"></div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label ">所属行业</label>
                                        <div class="layui-input-inline">
                                            <select name="industry"  lay-filter="industry">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                        <div class="layui-form-mid-red">*</div>
                                    </div>
                                    <div class="layui-inline company-input">
                                        <label class="layui-form-label">营业执照编号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="BUSS_CODE" lay-verify="" autocomplete="off"
                                                   class="layui-input">
                                        </div>
                                        <div class="width10"></div>
                                    </div>
                                    <div class="layui-inline person-input" style="display: none;">
                                        <label class="layui-form-label">身份证号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="ID_CARD" lay-verify="" autocomplete="off"
                                                   class="layui-input required_fields">
                                        </div>
                                        <div class="layui-form-mid-red">*</div>
                                    </div>
                                    <div class="layui-inline company-input">
                                        <label class="layui-form-label"></label>
                                        <div class="layui-input-inline">
                                        </div>
                                        <div class="width10"></div>
                                    </div>
                                    <div class="layui-inline company-input">
                                        <label class="layui-form-label">法人</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="LEG_REN" lay-verify="" autocomplete="off"
                                                   class="layui-input">
                                        </div>
                                        <div class="width10"></div>
                                    </div>
                                    <div class="layui-inline company-input">
                                        <label class="layui-form-label">联系电话</label>
                                        <div class="layui-input-inline">
                                            <input type="tel" name="LEG_TEL" lay-verify="" autocomplete="off"
                                                   class="layui-input">
                                        </div>
                                        <div class="width10"></div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">签订人</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="SIGN_REN" lay-verify="required" autocomplete="off"
                                                   class="layui-input required_fields">
                                        </div>
                                        <div class="layui-form-mid-red">*</div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">联系电话</label>
                                        <div class="layui-input-inline">
                                            <input type="tel" name="SIGN_TEL" lay-verify="required" autocomplete="off"
                                                   class="layui-input">
                                        </div>
                                        <!--<div class="layui-form-mid-red">*</div>-->
                                    </div>
                                </div>
                                <div class="layui-form-item contact-person-arr">
                                </div>
                                <div class="tenant-add-person">
                                    <span onclick="operate.addContactPerson(this)">
                                        <i class="fa fa-plus-circle" aria-hidden="true"></i>
                                        <span>增加联系人</span>
                                    </span>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">通讯地址</label>
                                    <div class="layui-input-block">
                                        <textarea name="ADDRESS" placeholder="请输入通讯地址" class="layui-textarea"></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="quote-other-info">
                            <div class="quote-title">
                                <i class="fa fa-circle-o" aria-hidden="true"></i>
                                <span>其他关键信息</span>
                            </div>
                            <div class="other-info-box">
                                <div class="attachment-info-box">
                                    <!--<div class="attachment-administer">
                                    <span>
                                        <i class="fa fa-cloud-upload" aria-hidden="true"></i>
                                        <span id="upload">上传附件</span>
                                        <div class="layui-upload-list" id="imgList"></div>
                                    </span>
                                    </div>-->
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn layui-btn-normal" id="testList">选择多文件</button>
                                        <div class="layui-upload-list">
                                            <table class="layui-table">
                                                <thead>
                                                <tr>
                                                    <th>缩略图</th>
                                                    <th>文件名</th>
                                                    <th>大小</th>
                                                    <th>状态</th>
                                                    <th>操作</th>
                                                </tr></thead>
                                                <tbody id="demoList"></tbody>
                                            </table>
                                        </div>
                                        <button type="button" class="layui-btn" id="testListAction">开始上传</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="tab-body">
                    <div>
                        <div class="quote-contract-info">
                            <div class="quote-title">
                                <i class="fa fa-circle-o" aria-hidden="true"></i>
                                <span>贷款信息</span>
                            </div>
                            <div class="contract-setting layui-row">
                                <div class="layui-col-md9">
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">借款金额：</label>
                                            <div class="layui-input-inline">
                                                <input type="number" name="LOAN_PRICE" lay-verify=""
                                                       autocomplete="off" value="0.00" placeholder="请输入借款金额" class="layui-input">
                                                <span class="input-label-unit">元</span>
                                            </div>
                                            <!--<span class="input-label-unit">元/㎡·天</span>-->
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">借款利率：</label>
                                            <div class="layui-input-inline layui-input-longer">
                                                <input type="number" name="BORROW_INTEREST_RATE" lay-verify=""
                                                       autocomplete="off" class="layui-input">
                                                <span class="input-label-unit">%</span>
                                                <span class="input-label-mon">日利率</span>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">借款期限：</label>
                                            <div class="layui-input-inline layui-input-longer">
                                                <input type="number" name="BORROW_PERIOD" lay-verify=""
                                                       autocomplete="off" class="layui-input">
                                                <span class="input-label-unit">天</span>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">滞纳金利率：</label>
                                            <div class="layui-input-inline layui-input-longer">
                                                <input type="number" name="LATE_PAYMENT_RATE" lay-verify=""
                                                       autocomplete="off" class="layui-input">
                                                <span class="input-label-unit">%</span>
                                                <span class="input-label-mon">日利率</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                               <!-- <div class="layui-col-md6 contract-setting-body contract-setting-center">
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">合同签订日期：</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" id="contract-signing-date"
                                                       placeholder="yyyy-MM-dd">
                                                <span class="input-label-unit-icon"><i class="fa fa-calendar"
                                                                                       aria-hidden="true"></i></span>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">合同计租日期：</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" id="contract-rent-date"
                                                       placeholder="yyyy-MM-dd">
                                                <span class="input-label-unit-icon"><i class="fa fa-calendar"
                                                                                       aria-hidden="true"></i></span>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">合同结束日期：</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" id="contract-finish-date"
                                                       placeholder="yyyy-MM-dd">
                                                <span class="input-label-unit-icon"><i class="fa fa-calendar"
                                                                                       aria-hidden="true"></i></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-btn-group">
                                        <a class="layui-btn layui-btn-primary layui-btn-small"
                                           onclick="operate.showDiscount(1);">一年</a>
                                        <a class="layui-btn layui-btn-primary layui-btn-small"
                                           onclick="operate.showDiscount(3);">三年</a>
                                        <a class="layui-btn layui-btn-primary layui-btn-small"
                                           onclick="operate.showDiscount(5);">五年</a>
                                    </div>
                                    <div style="margin-bottom: 10px"></div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">滞纳金比率：</label>
                                        <div class="layui-input-inline layui-input-extra-content" style=" height: 25px;">
                                            <select name="late_payment_rate" lay-filter="unit">
                                                <option value="0">比率</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">剩余本金：</label>
                                        <div class="layui-input-inline layui-input-longer">
                                            &lt;!&ndash;<div class="layui-input-inline">&ndash;&gt;
                                            <input type="number" name="remaining_price" lay-verify=""
                                                   autocomplete="off" class="layui-input">
                                            <span class="input-label-unit">‰/天</span>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">滞纳金执行日：</label>
                                        <div class="layui-input-inline layui-input-extra-content" style=" height: 25px;">
                                            <input type="number" name="late_pay_date" lay-verify=""
                                                   autocomplete="off" class="layui-input">
                                            <span class="input-label-unit">日</span>
                                            <span class="" style="position: absolute;top: 3px;right: -60px;z-index: 1;">收费日后</span>
                                        </div>
                                    </div>
                                </div>-->
                                <div class="layui-clear"></div>
                            </div>
                            <div class="contract-setting layui-row">
                                <div class="layui-block contract-remark">
                                    <label class="layui-form-label" style="width: auto;">备注信息：</label>
                                    <div class="layui-input-block" style="margin-left: 80px;">
                                        <textarea name="remark" placeholder="请输入合同的备注信息" class="layui-textarea"></textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-clear"></div>
                        </div>
                        <div class="quote-rent-detail" style="display: none">
                            <div class="quote-title">
                                <i class="fa fa-circle-o" aria-hidden="true"></i>
                                <span>借款明细</span>
                                <a onclick="operate.createRentDetail()"
                                   class="create-rent-detail-btn layui-btn layui-btn-primary layui-btn-small">
                                    <i class="fa fa-bar-chart" aria-hidden="true"></i>
                                    <span>生成借款明细</span>
                                </a>
                                <div class="layui-layer-content">Tips：合同信息修改后请点击左侧“生成借款明细”按钮重新生成借款信息。</div>
                                <a onclick="operate.editRentDetail()" class="layui-btn edit-rent-detail-btn">修改明细</a>
                                <div class="edit-rent-detail-btngroup">
                                    <a onclick="operate.cancelEditRentDetail()"
                                       class="layui-btn layui-btn-primary">取消</a>
                                    <a onclick="operate.saveEditRentDetail()" class="layui-btn">保存</a>
                                </div>
                            </div>
                            <div class="quote-rent-detail-list">
                                <ul class="container-rent-detail-list">
                                    <li>
                                        <div>
                                            <span>区间</span>
                                            <span></span>
                                        </div>
                                        <div>
                                            <span>付款日</span>
                                            <span></span>
                                        </div>
                                        <div>
                                            <span>滞纳金</span>
                                            <span class="label-unit-money">元/天</span>
                                        </div>
                                        <!--<div>
                                            <span>基础单价</span>
                                            <span class="label-unit-money">元/㎡·天</span>
                                        </div>-->
                                        <div>
                                            <span>最终金额</span>
                                            <span class="label-unit-money">元</span>
                                        </div>
                                        <!--<div>
                                            <span>优惠</span>
                                            <span class="label-unit-money">元</span>
                                        </div>-->
                                    </li>
                                </ul>
                                <div class="no-data-tips">
                                    <span>暂无数据</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <blockquote class="blockquote-bottom">
        <div class="blockquote-bottom-item">
            <a class="layui-btn layui-btn-primary layui-btn-small cancelBtn" onclick="operate.cancel();">取消</a>
            <a class="layui-btn layui-btn-small layui-btn-normal temporaryStorageBtn" onclick="operate.submit(this,0);">提交</a>
            <!--<a class="layui-btn layui-btn-small layui-btn-disabled submitBtn" onclick="operate.submit(this, 0);">提交</a>-->
        </div>
    </blockquote>
</form>
<script type="text/javascript" src="../../static/layer/layui.js"></script>
<script type="text/javascript" src="../../static/js/common/dateUtils.js"></script>
<script type="text/javascript" src="../../static/js/common/typeUtils.js"></script>
<script type="text/javascript" src="../../static/js/common/queryUtils.js"></script>
<script>
    var $, element, layer, laydate, form;
    var tips = false;   // 合同信息生成明细修改提示状态
    var ftype = 1;  // 支付按月还是按日 0按日 1按月
    var today = DateUtils.dateFormat(new Date(), "yyyy-MM-dd"); // 今天的日期
    var uploadfiles = new Array(); // 要上传的文件列表路径
    layui.use(['jquery', 'element', 'layer', 'laydate', 'form', 'upload'], function () {
        // 加载元素控件
        $ = layui.jquery, element = layui.element, layer = layui.layer, laydate = layui.laydate, form = layui.form;
        var upload = layui.upload;

        // 租赁方式单选框点击事件
        form.on('radio(rent-type)', function (data) {
            if (data.value == "0") {
                $(".person-input").hide();
                $(".company-input").show();
            } else if (data.value == "1") {
                $(".company-input").hide();
                $(".person-input").show();
            }
        });
        //多文件列表示例
        var files;
        var demoListView = $('#demoList')
            , uploadListIns = upload.render({
            elem: '#testList'
            , url: '/servlet/UploadHandleServlet'
            // ,accept: 'file'
            , multiple: true
            , auto: false
            , bindAction: '#testListAction'
            , choose: function (obj) {
                files = obj.pushFile(); //将每次选择的文件追加到文件队列
                //读取本地文件
                obj.preview(function (index, file, result) {
                    var tr = $(['<tr id="upload-' + index + '">'
                        , '<td><img src="' + result + '" alt="' + file.name + '" class="layui-upload-img"></td>'
                        , '<td>' + file.name + '</td>'
                        , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                        , '<td>等待上传</td>'
                        , '<td>'
                        , '<button class="layui-btn layui-btn-mini demo-reload layui-hide">重传</button>'
                        , '<button class="layui-btn layui-btn-mini layui-btn-danger demo-delete">删除</button>'
                        , '</td>'
                        , '</tr>'].join(''));

                    //单个重传
                    tr.find('.demo-reload').on('click', function () {
                        obj.upload(index, file);
                        return false;
                    });

                    //删除
                    tr.find('.demo-delete').on('click', function () {
                        delete files[index]; //删除对应的文件
                        tr.remove();
                    });

                    demoListView.append(tr);
                });
            }
            , done: function (res, index, upload) {
                if (res.errcode == 0) { //上传成功
                    var obj = {};
                    obj.name = res.data.fileName;
                    obj.size = res.data.fileSize;
                    obj.ext = res.data.extName;
                    obj.url = res.data.fileUrl;
                    uploadfiles.push(obj);
                    var tr = demoListView.find('tr#upload-' + index)
                        , tds = tr.children();
                    tds.eq(3).html('<span style="color: #5FB878;">上传成功</span>');
                    tds.eq(4).html(''); //清空操作
                    delete files[index]; //删除文件队列已经上传成功的文件
                    return;
                }
                this.error(index, upload);
            }
            , error: function (index, upload) {
                var tr = demoListView.find('tr#upload-' + index)
                    , tds = tr.children();
                tds.eq(3).html('<span style="color: #FF5722;">上传失败</span>');
                tds.eq(4).find('.demo-reload').removeClass('layui-hide'); //显示重传
            }
        });

        init.initUser();
        init.initContractDate(today,today,today);
        init.initInputChange();//输入框绑定时事件
        init.initIndustry();//初始所属行业
    });
    //初始化方法
    var init = {
        // 初始化当前登录用户
        initUser: function () {
            $.ajax({
                url: "/happuser/userInfo",
                data: {},
                dataType: "json",
                type: "post",
                async: false,
                success: function (res) {
                    if (res.errcode === "0") {
                        $(".user_name").html(res.data.name);
                    } else if (res.errcode === "1") {
                        layer.msg(res.errmsg, function () {
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.error(XMLHttpRequest.status);
                    console.error(XMLHttpRequest.readyState);
                    console.error(textStatus);
                }
            });
        },
        //初始化签订 计租 时间
        // 初始化合同签订日期、计租日期、结束日期
        initContractDate: function (aDate, bDate, cDate) {
            // 初始化合同签订日期
            laydate.render({
                elem: '#contract-signing-date',
                btns: ['now'],   // 只显示今天按钮
                done: function (value, date, endDate) {
                    operate.changeDate('signing', value);
                }
            });
            // 给合同签订日期设置初始值为今天
            $("#contract-signing-date").val(aDate);    // 日期工具类格式化日期
            // 初始化合同计租日期
            laydate.render({
                elem: '#contract-rent-date',
                btns: ['now'],   // 只显示今天按钮
                done: function (value, date, endDate) {
                    operate.changeDate('start', value);
                }
            });
            // 给合同计租日期设置初始值为今天
            $("#contract-rent-date").val(bDate);    // 日期工具类格式化日期
            // 初始化合同结束日期
            laydate.render({
                elem: '#contract-finish-date',
                btns: ['now'],   // 只显示今天按钮
                done: function (value, date, endDate) {
                    operate.changeDate('finish', value);
                }
            });
            // 给合同结束日期设置初始值为今天
            $("#contract-finish-date").val(cDate);    // 日期工具类格式化日期
        },
        // 所有的折扣的输入框绑定输入事件
        initInputChange: function () {
            $(".contract-discount-body").find("input").unbind("input");
            $(".contract-discount-body").find("input").on("input", function () {
                change.change($(this));
            });
        },
        // 初始化所属行业信息
        initIndustry: function () {
            $.ajax({
                url: "/dictionary/findByCode",
                data: {code: "PRO_007"},
                dataType: "json",
                type: "post",
                async: false,
                success: function (res) {
                    if (res.errcode === "0") {
                        var data = res.data;
                        if (!!data) {
                            for (var i = 0; i < data.length; i++) {
                                var str = '<option value="' + data[i].ID + '">' + data[i].NAME + '</option>';
                                $("select[name='industry']").append(str);
                            }
                        }
                        form.render("select");
                    } else if (res.errcode === "1") {
                        layer.msg(res.errmsg, function () {
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.error(XMLHttpRequest.status);
                    console.error(XMLHttpRequest.readyState);
                    console.error(textStatus);
                }
            });
        },
    };
    //操作方法
    var operate = {
        // 通过点击几年的按钮显示不同的递增率和折扣 type为几年，1/3/5
        showDiscount: function (type) {
            $("#contract-finish-date").val(DateUtils.getNextNYearDate($("#contract-rent-date").val(), type));
            operate.appendDiscountSet(type);
            change.change();
        },
        // 通过改变日期显示不同的递增率和折扣 type为改变的哪个时间，date为时间
        changeDate: function (type, date) {
            var sDate = $("#contract-rent-date").val();
            var eDate = $("#contract-finish-date").val();
            if (type === 'start') {
                sDate = date;
            } else if (type === 'finish') {
                eDate = date;
            }
            var years = DateUtils.getYearsDiff(sDate, eDate);
            operate.appendDiscountSet(years);
            change.change();
        },
        // 克隆方法
        clone: function (obj) {
            var a = $(obj).parent().parent().find(".clone-box:last");
            var index = $(a).attr("data-index");
            var b = a.clone(true);
            $(b).attr("data-index", parseInt(index) + 1);
            $(b).find(".fa-plus-circle").hide();
            $(b).find(".fa-times-circle").show();

            $(b).find("textarea[name='room']").val("");
            $(b).find("textarea[name='room']").attr("data-id", "");
            $(b).find(".box-container dd").removeClass("layui-this");
            $(b).find(".building-box-container").empty();
            $(b).find(".building-box-container").hide();
            $(b).find(".unit-box-container").empty();
            $(b).find(".unit-box-container").hide();
            $(b).find(".floor-box-container").empty();
            $(b).find(".floor-box-container").hide();
            $(b).find(".room-box-container").empty();
            $(b).find(".room-box-container").hide();

            $(b).find(".room-area-single").empty();
            $(b).find(".room-area").hide();

            $(obj).parent().parent().append(b);
            form.render("select");
            $("input[name='securityDepositMoney']").val(calculate.securityDeposit().toFixed(2));
        },
        // 克隆押金类型方法
        cloneBondType: function (obj) {
            var str = '<div class="layui-inline">\n' +
                '          <div class="layui-input-inline layui-input-short">\n' +
                '              <input type="text" name="securityDepositName" placeholder="押金名称" lay-verify=""\n' +
                '                     autocomplete="off" class="layui-input">\n' +
                '          </div>\n' +
                '          <div class="layui-input-inline layui-input-longer">\n' +
                '              <input type="number" name="securityDepositPrice" lay-verify=""\n' +
                '                     autocomplete="off" class="layui-input">\n' +
                '              <span class="input-label-unit">元</span>\n' +
                '          </div>\n' +
                '          <i class="fa fa-times-circle" onclick="operate.remove(this, 1);" aria-hidden="true"></i>\n' +
                '      </div>';
            $(".bond-list").append(str);
        },
        // 增加联系人
        addContactPerson: function (obj) {
            var str = '<div class="contact-person-box">\n' +
                '          <div class="layui-inline">\n' +
                '              <label class="layui-form-label">联系人</label>\n' +
                '              <div class="layui-input-inline">\n' +
                '                  <input type="text" name="lxr-name" lay-verify="required" autocomplete="off" class="layui-input">\n' +
                '              </div>\n' +
                '              <div class="layui-form-mid-red">*</div>\n' +
                '          </div>\n' +
                '          <div class="layui-inline">\n' +
                '              <label class="layui-form-label">联系电话</label>\n' +
                '              <div class="layui-input-inline">\n' +
                '                  <input type="tel" name="lxr-tel" lay-verify="required" autocomplete="off" class="layui-input">\n' +
                '              </div>\n' +
                '              <div class="layui-form-mid-red">*</div>\n' +
                '              <i class="fa fa-times-circle" aria-hidden="true" onclick="operate.remove(this, 2);"></i>\n' +
                '          </div>\n' +
                '      </div>';
            $(obj).parent().parent().find(".contact-person-arr").append(str);
        },
        // 移除当前信息的方法，tier为几层父级
        remove: function (obj, tier) {
            switch (tier) {
                case 1:
                    $(obj).parent().remove();
                    break;
                case 2:
                    $(obj).parent().parent().remove();
                    break;
                case 3:
                    $(obj).parent().parent().remove();
                    break;
            }
        },
        // 通过年数生成该显示多少年的设置(实际)
        appendDiscountSet: function (years) {
            // 当前租金
            var unitPrice = $("input[name='rentSinglePrice']").val();
            if (!unitPrice) {
                unitPrice = 0;
            }

            init.initInputChange();
            // change.rentOrdiscountOrIncreasingChange();
        },
        // 新增租金明细
        createRentDetail: function () {
            var flag = true;    // each()中return只跳出循环，加标志位跳出方法
            /* 验证合同信息是否填全 */
            var loan_price = $("input[name='loan_price']").val();//借款金额
            var payment_reminder_day = $("input[name='payment_reminder_day']").val();
            var prePayDays = $("input[name='prePayDays']").val();//付息日期
            var borrow_Interest_Rate = $("input[name='borrow_Interest_Rate']").val();//借款利率
            // var late_payment_rate = $("input[name='late_payment_rate']").val();//滞纳金比率
            var remaining_price = $("input[name='remaining_price']").val();//剩余本金
            var late_pay_date = $("input[name='late_pay_date']").val();//滞纳金执行日
            if (!loan_price || !payment_reminder_day || !prePayDays || !borrow_Interest_Rate || !remaining_price || !late_pay_date) {
                layer.alert('合同信息未填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                return false;
            }

            /* 验证合同时间是否正确 */
            var sDate = $("#contract-rent-date").val();
            var eDate = $("#contract-finish-date").val();
            var compare = DateUtils.compareTime(sDate, eDate);
            if (compare !== -1) {
                layer.alert('合同结束时间必须大于开始时间', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                return false;
            }


            /* 将提示的状态改为true */
            tips = true;

            // 将暂无数据隐藏
            $(".quote-rent-detail-list").find(".no-data-tips").remove();

            $(".edit-rent-detail-btn").show();
            $(".edit-rent-detail-btngroup").hide();

            // 生成租金详情
            // 根据单位来 0 - 4
            change.createRentDetailTable();

            /* 显示修改明细的按钮 */
            $(".edit-rent-detail-btn").fadeIn(300);

            $(".layui-btn-disabled").removeClass("layui-btn-disabled");

        },
        // 修改租金明细
        editRentDetail: function () {
            layer.confirm('点击编辑，表单数据不再和基础数据联动，提交数据以表单为准', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {

                $(".rent-detail-item-mzq").each(function () {
                    $(this).remove();
                });

                $(".container-rent-detail-list").find(".rent-detail-item").each(function (index, elem) {
                    if ($(this).hasClass("rent-detail-item-yj")) {
                        var name = $(this).find("div").eq(0).find("span").html();
                        var pDate = $(this).find("div").eq(1).find("span").html();
                        var zzje = $(this).find("div").eq(6).find("span.real-zjje").html();
                        var beizhu = $(this).find("div").eq(7).find("span").html();
                        var fkfpType = $(this).find("div").eq(6).find("span.fkfp-span").data("type");
                        var kfp = $(this).find("div").eq(6).find("span.fkfp-kfp").html();
                        var bkfp = $(this).find("div").eq(6).find("span.fkfp-bkfp").html();
                        var kfpJe = $(this).find("div").eq(6).find("span.fkfp-kfp-je").html();

                    } else {
                        var year = $(this).data("year");
                        var jcdj = $("input[name='rentSinglePrice']").val();
                       /* if (year != 1) {
                            jcdj = $(".contract-setting-discount").find(".contract-discount-body").eq(year - 2).find(".after-discount-money").html();
                        }*/
                        var sDate = $(this).find("div").eq(0).find("span").html().substring(0, 10);
                        var eDate = $(this).find("div").eq(0).find("span").html().substring(13, 23);
                        var pDate = $(this).find("div").eq(1).find("span").html();
                        var znj = 0;
                        if ($(this).find("div").eq(2).find("span").html() != undefined) {
                            znj = $(this).find("div").eq(2).find("span").html();
                        }
                        var zzje = $(this).find("div").eq(3).find("span").html();//最终金额
                        var beizhu = $(this).find("div").eq(4).find("span").html();


                        var str = '<li class="rent-detail-item" data-year="' + year + '" data-jcdj="' + jcdj + '">\n' +
                            '          <div>\n';

                        if (index != $(".container-rent-detail-list").find(".rent-detail-item").length - 1) {
                            str += '              <i onclick="operate.addRentItem(this);" class="fa fa-plus item-add" aria-hidden="true"></i>\n';
                        }

                        str += '              <div class="layui-input-inline">\n';
                        str += '                  <input type="text" data-value="' + sDate + '" value="' + sDate + '" class="layui-input layui-date startDate">\n' +
                               '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n';
                        str += '              </div>\n' +
                            '              -\n' +
                            '              <div class="layui-input-inline">\n';
                            str += '                  <input type="text" data-value="' + eDate + '" value="' + eDate + '" class="layui-input layui-date endDate">\n' +
                                '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n';
                        str += '              </div>\n' +
                            '          </div>\n' +
                            '          <div>\n' +
                            '              <div class="layui-input-inline">\n' +
                            '                  <input type="text" value="' + pDate + '" class="layui-input layui-date payDate">\n' +
                            '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
                            '              </div>\n' +
                            '          </div>\n' +
                            '          <div>\n' +
                            '              <div class="layui-input-inline">\n' +
                            '                  <input type="number" name="edit-znj" value="' + znj + '" autocomplete="off" class="layui-input">\n' +
                            '              </div>\n' +
                            '          </div>\n';
                        str += '          <div>\n' +
                            '              <div class="layui-input-inline">\n' +
                            '                  <input type="number" oninput="" name="edit-zzje" value="' + zzje+ '" autocomplete="off" class="layui-input">\n' +
                            '              </div>\n' +
                            '          </div>\n' +
                            '          <div class="discounts-select">\n';
                        if (index < $(".container-rent-detail-list").find(".rent-detail-item").length - 1) {
                            str += '              <i onclick="operate.remove(this, 3);" class="fa fa-times" aria-hidden="true"></i>\n';
                        }
                        str += `          </div>
                                  </li>`;
                        if ( $(this).find("div").eq(2).find("span").html() != undefined && $(this).find("div").eq(3).find("span").html() != undefined) {
                            $(".container-rent-detail-list").append(str);
                        }
                    }
                    // 将编辑的租金详情隐藏
                    $(this).remove();
                });
                $(".layui-date").each(function () {
                    laydate.render({
                        elem: this,
                        btns: ['now']   // 只显示今天按钮
                    });
                });
                form.render("select");
                // change.editInputChange();
                layer.close(index);
                $(".edit-rent-detail-btn").hide();
                $(".edit-rent-detail-btngroup").show();
            });
        },
        // 增加租金明细单条
        addRentItem: function (obj) {
            var year = $(obj).parent().parent().data("year");
            var jcdj = $(obj).parent().parent().data("jcdj");
            var date = $(obj).parent().parent().find(".endDate").val();
            var fpzb = $("input[name='unit-fkfp']").val();
            var str = '<li class="rent-detail-item" data-year="' + year + '" data-jcdj="' + jcdj + '">\n' +
                '          <div>\n' +
                '              <i onclick="operate.addRentItem(this);" class="fa fa-plus item-add" aria-hidden="true"></i>\n' +
                '              <div class="layui-input-inline">\n' +
                '                  <input type="text" data-value="" value="' + date + '" class="layui-input layui-date startDate">\n' +
                '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
                '              </div>\n' +
                '              -\n' +
                '              <div class="layui-input-inline">\n' +
                '                  <input type="text" data-value="" value="' + date + '" class="layui-input layui-date endDate">\n' +
                '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
                '              </div>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <div class="layui-input-inline">\n' +
                '                  <input type="text" value="' + date + '" class="layui-input layui-date payDate">\n' +
                '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
                '              </div>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <div class="layui-input-inline">\n' +
                '                  <input type="number" name="edit-znj" value="0" autocomplete="off" class="layui-input">\n' +
                '              </div>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <div class="layui-input-inline">\n' +
                '                  <input type="number" oninput="change.editInputChange(this, 2);" name="edit-zzje" value="0" autocomplete="off" class="layui-input">\n' +
                '              </div>\n' +
                '          </div>\n' +
                '          <div class="discounts-select">\n' +
                '              <i onclick="operate.remove(this, 3);" class="fa fa-times" aria-hidden="true"></i>\n' +
                '          </div>\n' +
                '      </li>';
            $(obj).parent().parent().after(str);
            $(".layui-date").each(function () {
                laydate.render({
                    elem: this,
                    btns: ['now']   // 只显示今天按钮
                });
            });
            form.render('select');
        },
        // 取消修改租金明细
        cancelEditRentDetail: function () {
            layer.confirm('是否放弃手动修改所填的数据，重新生成账单？', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {
                // 生成租金详情
                change.createRentDetailTable();
                layer.close(index);
                $(".edit-rent-detail-btngroup").hide();
                $(".edit-rent-detail-btn").show();
            });
        },
        // 保存修改的租金明细
        saveEditRentDetail: function () {
            // 生成租金详情
            layer.confirm('是否保存所修改的数据？', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {
                // 保存生成租金详情
                change.saveRentDetailTable();
                layer.close(index);
                $(".edit-rent-detail-btngroup").hide();
                $(".edit-rent-detail-btn").show();
            });
        },
        // 取消新建合同
        cancel: function () {
            // 当你在iframe页面关闭自身时
            var index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
            parent.layer.close(index); // 再执行关闭
        },
        // 提交合同前验证
        validate: function () {
            var zlf = $("input[name='TRNANTRY']:checked").val();    // 租赁方
            var flag=true;

            if (zlf == 0) {
                var gsm = $("input[name='COMPANY']").val();    // 公司名
                if (!gsm) {
                    layer.alert('公司名不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                    return false;
                }
            } else if (zlf == 1) {
                var xm = $("input[name='NAME']").val();    // 姓名
                if (!xm) {
                    layer.alert('姓名不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                    return false;
                }
                var sfz = $("input[name='ID_CARD']").val();    // 身份证号
                if (!sfz) {
                    layer.alert('身份证号不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                    return false;
                }
            }

            var sshy = $("select[name='industry']").val();    // 所属行业
            if (!sshy) {
                layer.alert('所属行业不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                return false;
            }


            var lxdh = $("input[name='SIGN_TEL']").val();    // 联系电话
            /*if (!lxdh) {
                layer.alert('联系电话不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                return false;
            }*/

            $("input[name='lxr-tel']").each(function () {
                if (!$(this).val()) {
                    layer.alert('联系人电话不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                    flag = false;
                    return false;
                }
            });

            if (!flag) {
                return false;
            }

            return true;

        },
        // 暂存合同
        temporaryStorage: function (obj) {
            operate.submit(obj, 1);
        },
        // 变更合同
        changeContract: function (obj) {
            operate.submit(obj, 2);
        },
        // 提交当期合同
        submit: function (obj, submitType) {
            if (!$(obj).hasClass("layui-btn-disabled")) {

                if (submitType == 0) {
                    var flag = operate.validate();
                    if (!flag) {
                        return false;
                    }
                }

                // 联系人数组
                var contacts = new Array();
                $(".contact-person-box").each(function () {
                    var contact = {};
                    contact.CONTACTS_NAME = $(this).find("input[name='lxr-name']").val();
                    contact.CONTACTS_TEL = $(this).find("input[name='lxr-tel']").val();
                    contacts.push(contact);
                });

                var contractNum = $("input[name='CONTRACT_NUM']").val();
                var lease = $("input[name='TRNANTRY']:checked").val();
                var company = $("input[name='COMPANY']").val();
                var name = $("input[name='NAME']").val();
                var byname = $("input[name='byname']").val();
                var industry = $("select[name='industry']").val();
                var buss_code = $("input[name='BUSS_CODE']").val();
                var id_card = $("input[name='ID_CARD']").val();
                var leg_name = $("input[name='LEG_REN']").val();
                var leg_tel = $("input[name='LEG_TEL']").val();
                var address = $("textarea[name='ADDRESS']").val();
                var sign_ren = $("input[name='SIGN_REN']").val();
                var sign_tel = $("input[name='SIGN_TEL']").val();
                var LOAN_PRICE=$("input[name='LOAN_PRICE']").val();//借款金额
                var repayment=$("select[name='repayment']").val();//还款方式
                var BORROW_INTEREST_RATE=$("input[name='BORROW_INTEREST_RATE']").val();//借款利率
                var BORROW_PERIOD=$("input[name='BORROW_PERIOD']").val();//借款期限
                var prePayDays = $("input[name='prePayDays']").val();//付息日期
                var payment_reminder_day = $("input[name='payment_reminder_day']").val();//付款提醒日期
                var LATE_PAYMENT_RATE = $("input[name='LATE_PAYMENT_RATE']").val();//滞纳金比率
                var dzlx = $("input[name='dzlx']:checked").val();
                var info = $("textarea[name='remark']").val();
                var con_date = $("#contract-signing-date").val();
                var con_hr_date = $("#contract-rent-date").val();
                var con_end_date = $("#contract-finish-date").val();
                var con_outf_date = $("#before-unable-date-start").val();
                var con_outl_date = $("#after-unable-date-end").val();
                var state = '0';
                if (submitType == 1) {
                    state = '93fc91b97d144550aed7ea1c01dd3w03';
                }

                var fkfp = $("input[name='fkfp']:checked").val();

                var late_fee = $("input[name='unit-znj']").val();

                // 租户基本信息
                var tenant = {};
                if (lease == 0) {
                    tenant.COMPANY_NAME = company;
                    tenant.BUSINESS_LICENSE = buss_code;
                } else if (lease == 1) {
                    tenant.COMPANY_NAME = name;
                    tenant.BUSINESS_LICENSE = id_card;
                }
                tenant.INDUSTRY_ID = industry;
                tenant.LEGAL_PERSON_NAME = leg_name;
                tenant.LEGAL_PERSON_TEL = leg_tel;
                tenant.CONTRACT_ADDRESS = address;
                tenant.BYNAME = byname;

                // 合同基本信息
                var contract = {};
                contract.CONTRACT_NUM = contractNum;
                contract.TRNANTRY = lease;
                contract.SIGNER = sign_ren;
                contract.SIGNER_TEL = sign_tel;
                contract.INFO = info;
                contract.INCREAS_TYPE = dzlx;
                contract.LATE_FEE = late_fee;
                contract.CON_DATE = con_date;
                contract.CON_HR_DATE = con_hr_date;
                contract.CON_END_DATE = con_end_date;
                contract.FKFP_TYPE = fkfp;
                contract.CHECK_STATE = "01";
                contract.STATE = state;
                contract.BILL_HTML = $(".container-rent-detail-list").html();
                contract.LOAN_PRICE=LOAN_PRICE;
                contract.repayment=repayment;
                contract.BORROW_INTEREST_RATE=BORROW_INTEREST_RATE;
                contract.BORROW_PERIOD=BORROW_PERIOD;
                contract.payment_reminder_day=payment_reminder_day;
                contract.LATE_PAYMENT_RATE=LATE_PAYMENT_RATE;//滞纳金利率
                contract.payment_reminder_day=payment_reminder_day;

                // 账单数组
                var bills = new Array();
                // 贷款账单
                $(".rent-detail-item").each(function (index) {
                    
                    if (!!$(this).find("div").eq(2).find("span").html()) {
                        var bill = {};
                        bill.START_DATE = $(this).find("div").eq(0).find("span").html().substring(0, 10);
                        bill.END_DATE = $(this).find("div").eq(0).find("span").html().substring(13, 23);
                        bill.PAY_DATE = $(this).find("div").eq(1).find("span").html()
                        var znj = $(this).find("div").eq(2).find("span").html();//滞纳金
                        var zzje = $(this).find("div").eq(3).find("span").html();//最终金额
                        if (znj == " - ") {
                            znj = 0;
                        }
                        bill.LATE_FEE = znj;
                        bill.PRICE = zzje;
                        bill.INFO = $(this).find("div").eq(7).find("span").html();
                        bill.BILL_TYPE = 10;//账单类型  贷款10
                        bill.BILL_NAME = "贷款";
                        bill.SORT = index;
                        bill.PROPERTY_ID = "";
                        bill.STATE = '0';
                        bill.ACT_PAY_DATE = "";
                        bill.MAKE_BILL_TYPE = 0;
                        bill.ALLOT_BILL = 1;//0 公户 1 私户
                        bills.push(bill)
                    }
                });

                // 提醒数组
                var reminds = new Array();
                $(".property-tx-detail-item").each(function (index) {
                    var tx = {};
                    tx.START_DATE = $(this).find("div").eq(0).find("span").html().substring(0, 10);
                    tx.END_DATE = $(this).find("div").eq(0).find("span").html().substring(13, 23);
                    tx.PAY_DATE = $(this).find("div").eq(1).find("span").html();
                    tx.TYPE = $(this).find("div").eq(2).find("span").html();
                    reminds.push(tx);
                });

                if (submitType == 2) {
                    var BILL_ID = '';
                    $("input[name='BILL_ID']").each(function (index) {
                        if ($(this).is(':checked')) {
                            BILL_ID += $(this).val() + ",";
                        }
                    });
                    BILL_ID = BILL_ID.replace(/(.*)[,，]$/, '$1');
                    contract.CONTRACT_ID = contractId;
                    contract.BILL_ID = BILL_ID;
                }



                var data = {};
                data.CONTACTS = contacts;
                data.TENANT = tenant;
                data.CONTRACT = contract;
                data.BILL = bills;
                data.REMINDS = reminds;
                // data.ATTACHMENT = uploadfiles;
                // data.COLLECTION = collectionData;

                // console.log(uploadfiles);
                // console.log(JSON.stringify(contract));
                // console.log(JSON.stringify(bills));
                // console.log(JSON.stringify(rooms));
                // console.log(JSON.stringify(propertys));
                // console.log(JSON.stringify(collectionData));
                var sendData = {};
                sendData.DATA = JSON.stringify(data);
                if (submitType == 0) {
                    layer.msg('确认新建业务吗', {
                        time: 0
                        , btn: ['确定', '取消']
                        , shade: 0.3
                        , yes: function (index) {
                            layer.close(index); // 关闭当前提示框
                            var i = parent.layer.getFrameIndex(window.name);
                            // layer.alert(JSON.stringify(data));
                            $.ajax({
                                url: "/LoanController/save",
                                data: sendData,
                                dataType: "json",
                                type: "post",
                                async: false,
                                success: function (res) {
                                    if (res.errcode === "0") {
                                        parent.layer.close(i);  // 关闭新建合同页面
                                        parent.layer.msg("保存成功");   // 父页面弹出保存成功
                                        if(!!parent.frames[1].reloadBussiness()){
                                            parent.frames[1].reloadBussiness();//刷新业务管理 审批中的业务
                                        }
                                        if(!!parent.frames[1].reloadCONID()){
                                            parent.frames[1].reloadCONID();//刷新审批事项
                                        }

                                    } else if (res.errcode === "1") {
                                        layer.msg("保存失败");
                                        /*layer.msg(res.errmsg, function () {
                                        });*/
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    layer.msg("保存失败");
                                    console.error(XMLHttpRequest.status);
                                    console.error(XMLHttpRequest.readyState);
                                    console.error(textStatus);
                                }
                            });
                        }
                    });
                } else if (submitType == 1) {

                } else if (submitType == 2) {

                }
            }
            return false;
        }
    };
    //改变方法
    var change = {
        // 有输入值改变
        change: function (obj) {
            // 如果状态为true的话显示小提示
            if (tips === true) {
                $(".quote-rent-detail").find(".quote-title").find(".layui-layer-content").fadeIn(200);
            }
            // 只有当data-type是unit-div里的输入框值改变的时候才去调用重新计算的方法
            if ($(obj).parent().parent().attr("data-type") === "unit-div") {
                change.rentOrdiscountOrIncreasingChange($(obj));
            }
            if ($(obj).attr("name") === "unit-discount") {
                change.rentOrdiscountOrIncreasingChange($(obj));
            }
        },
        // 生成租金详情
        createRentDetailTable: function () {
            $(".container-rent-detail-list .rent-detail-item-mzq").each(function () {
                $(this).remove();
            });
            $(".container-rent-detail-list .rent-detail-item").each(function () {
                $(this).remove();
            });
            var sDate = $("#contract-rent-date").val();
            var eDate = $("#contract-finish-date").val();
            var allDays = DateUtils.dateDiffInClude(sDate, eDate);
            var years = DateUtils.getYearsDiff(eDate, sDate);
            var startDate = sDate;
            var endDate = eDate;
            var prePayDay = parseInt($("input[name='prePayDays']").val());//付息日
            var repayment = parseInt($("select[name='repayment']").val());//还款方式
            if(repayment==1){//按月付息

            }
            var payDateType = $("select[name='fxrq']").val();//付款提醒日 0 固定 1 提前
            if (ftype != 0) {
                // 月
                var months = Math.ceil(DateUtils.getSpacingMonths(sDate, eDate) / parseInt(repayment));//按月付息

                if (parseInt(eDate.substring(8, 10)) >= parseInt(sDate.substring(8, 10))) {
                    months++;
                }
                for (var i = 0; i < months; i++) {
                    var payDate;//付款日
                    if (payDateType == 1) {
                        // 头一条租金按计租日收费 ——————————按照固定日收费
                        // payDate = $("#contract-rent-date").val();
                            startDate = DateUtils.dateFormat(new Date(DateUtils.addDay(1, new Date(endDate))), "yyyy-MM-dd");
                            payDate = DateUtils.addDay(0 - prePayDay, new Date(startDate));
                    } else if (payDateType == 0) {//固定日收费 此处但是保留

                        prePayDay = parseInt($("input[name='prePayDays']").val());
                        if (prePayDay < 10) {
                            prePayDay = "0" + prePayDay;
                        }
                        //计租日期 计算  第一个计租日期
                        payDate = startDate.substring(0, 7) + "-" + prePayDay;
                        if (i > 0) {
                            startDate = DateUtils.dateFormat(new Date(DateUtils.addDay(1, new Date(endDate))), "yyyy-MM-dd");
                            var y = startDate.substring(0, 4);
                            var m = startDate.substring(5, 7);
                            var d = DateUtils.getDaysOfMonth(y, m);
                            if (prePayDay > d) {
                                prePayDay = d;
                            }
                            payDate = startDate.substring(0, 7) + "-" + prePayDay;
                        }
                    }
                    endDate = DateUtils.dateFormat(new Date(DateUtils.addDay(-1, new Date(DateUtils.addMoth(startDate, parseInt(repayment))))), "yyyy-MM-dd");
                    if (i === months - 1) {
                        endDate = eDate;
                    }

                    var zzje = $("input[name='loan_price']").val();  //最终金额
                    var yearCount = DateUtils.getYearsDiff(startDate, sDate);
                    var borrow_Interest_Rate = $("input[name='borrow_Interest_Rate']").val();//借款利率
                    zzje=parseInt(borrow_Interest_Rate/100*zzje);
                    var dateDiff = DateUtils.dateDiffInClude(startDate, endDate);
                    // 计算账单最终 金额 单位是0
                    // zzje = Number(zjdj) * parseInt(ftype);
                    zzje = zzje.toFixed(2);
                    var znj=0;//滞纳金  借款金额的 千分之5
                    var remaining_price=parseInt($("input[name='remaining_price']").val());//滞纳金比率

                    var znj = (parseFloat($("input[name='loan_price']").val())*remaining_price/1000).toFixed(2);
                    if (!znj) {
                        znj = 0;
                    }
                    var dzl=0;
                    var zk=0;
                    var str = `<li class="rent-detail-item" data-year="${yearCount}">
                                  <div>
                                     <span>${startDate}-${endDate}</span>
                                  </div>
                                  <div>
                                      <span>${payDate}</span>
                                  </div>
                                  <div>
                                      <span>${znj}</span>
                                  </div>
                                  <div>
                                      <span>${zzje}</span>
                                  </div>
                                  <div>
                                      <span></span>
                                  </div>
                              </li>`;
                    if (zzje != "NaN" && zzje != undefined && zzje != null && zzje != "") {
                        $(".container-rent-detail-list").append(str);
                    }

                }
                //最后一次 归还所有本金
                startDate=$("#contract-rent-date").val();//归还本本机的开始时间 合同开始时间
                endDate=$("#contract-finish-date").val();//归还本本机的开始时间     合同结束时间
                payDate=$("#contract-finish-date").val();//归还本本机的开始时间    应付款时间
                zzje=parseFloat($("input[name='loan_price']").val()).toFixed(2);//归还的最后金额
                var str = `<li class="rent-detail-item" data-year="${yearCount}">
                                  <div>
                                     <span>${startDate}-${endDate}</span>
                                  </div>
                                  <div>
                                      <span>${payDate}</span>
                                  </div>
                                  <div>
                                      <span>${znj}</span>
                                  </div>
                                  <div>
                                      <span>${zzje}</span>
                                  </div>
                                  <div>
                                      <span></span>
                                  </div>
                              </li>`;
                if (zzje != "NaN" && zzje != undefined && zzje != null && zzje != "") {
                    $(".container-rent-detail-list").append(str);
                }
            }
        },
        // 固定日日期输入验证
        prePayDaysChange: function (obj) {
            if ($("select[name='fkrq']").val() == 1) {
                if ($(obj).val() < 1 || $(obj).val() > 30) {
                    $(obj).val("");
                    layer.msg("固定日期不能小于1或大于30", function () {
                    });
                }
            }
        },
        // 保存修改后的账单
        saveRentDetailTable: function () {

            var bs = $("#before-unable-date-start").val();
            var be = $("#before-unable-date-end").html();
            var as = $("#after-unable-date-start").html();
            var ae = $("#after-unable-date-end").val();

            $(".container-rent-detail-list").find(".rent-detail-item").each(function (index, elem) {

                var je = $(this).find("input[name='edit-zzje']").val();
                var fkfpStr = '';
                var fpblNum = $(this).find("input[name='unit-fkfp-num']").val();


                if ($(this).hasClass("rent-detail-item-yj")) {

                } else {
                    var yearCount = $(this).data("year");
                    var startDate = "";
                    startDate = $(this).find(".startDate").val();
                    var endDate = "";
                    endDate = $(this).find(".endDate").val();
                    var payDate = $(this).find(".payDate").val();
                    var znj = $(this).find("input[name='edit-znj']").val();
                    if (!znj) {
                        dzl = 0;
                    }
                    var zzje = $(this).find("input[name='edit-zzje']").val();
                    var beizhu = $(this).find("input[name='edit-beizhu']").val();

                    var str = '<li class="rent-detail-item" data-year="' + yearCount + '">\n' +
                        '          <div>\n' +
                        '              <span>' + startDate + ' - ' + endDate + '</span>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <span>' + payDate + '</span>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <span>' + znj + '</span>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <span>' + zzje + '</span>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <span>' + '' + '</span>\n' +
                        '          </div>\n' +
                        '      </li>';
                    $(this).remove();
                    $(".container-rent-detail-list").append(str);
                }
            });
        },
    };
</script>
</body>
</html>